home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00074_conditionsService parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  10.4 KB  |  375 lines

  1. -- 2001.01.27
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- establishes conditions; updates data settings accordingly.
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property main            -- main code directory object
  12. property dataManager     -- the data management and storage object
  13. property elements        -- a list of known conditions and their criteria
  14. property groups          -- a list of condition groupings with boolean flags
  15. property outcomes        -- a list of outcomes with condition criteria
  16.  
  17. property conditionStates -- a list of actual condition states obtained
  18. property groupStates     -- a list of condition groups and their status
  19.  
  20. ------------------------------------------------------------------------------------------------------
  21.  
  22. on new me,L
  23.   
  24.   -- (1) extract and check arguments:
  25.   
  26.   -- check for a parameter list:
  27.   if ilk(L) <> #propList then return ┬¼
  28.   [#error:#noParamListSupplied, #msg:"conditionsService:new"]
  29.   
  30.   -- a reference to the parent codebase is REQUIRED:
  31.   main = L[#main]
  32.   if (ilk(main) <> #instance) then return ┬¼
  33.   [#error:#noMainObjectSupplied, #msg:"conditionsService:new"]
  34.   
  35.   --------------------
  36.   
  37.   -- (2) obtain required data:
  38.   dataManager = main.getDataManager()
  39.   
  40.   elements = dataManager.getData([#set:#conditionElements])
  41.   groups   = dataManager.getData([#set:#conditionGroups])
  42.   outcomes = dataManager.getData([#set:#outcomes])
  43.   
  44.   --------------------
  45.   
  46.   -- (3) what is the status of each known condition element?
  47.   conditionStates = me.getConditionStates()
  48.   
  49.   --------------------
  50.   
  51.   -- (4) which groups of conditions actually exist?
  52.   
  53.   -- create a list to hold the status of each group:
  54.   groupStates = [:]
  55.   
  56.   -- examine the specified conditions for each group in turn:
  57.   repeat with i = 1 to count(groups)
  58.     
  59.     -- get the name and conditions listing for group i:
  60.     g  = getPropAt(groups,i)
  61.     cL = getAt(groups,i)
  62.     
  63.     -- for a group to be valid, ALL of the condition states it specifies
  64.     -- must be matched:
  65.     
  66.     -- set a boolean flag, and then test each condition listed within group g:
  67.     f = 1
  68.     repeat with j = 1 to count(cL)
  69.       
  70.       -- what is the name and specified state of the jth listed condition?
  71.       cn = getPropAt(cL,j)
  72.       v  = getAt(cL,j)
  73.       
  74.       -- what is the actual state of condition cn?
  75.       status = conditionStates[cn]
  76.       
  77.       -- IMPORTANT ASSUMPTION:
  78.       -- assume that unidentifed conditions have NOT been met!!!
  79.       if voidP(status) then status = 0
  80.       
  81.       -- does the required state for condition cn match its actual state?
  82.       if status = v then next repeat
  83.       
  84.       -- they didn't match - group g is out of luck:
  85.       f = 0
  86.       exit repeat
  87.       
  88.     end repeat
  89.     
  90.     -- store the validity or otherwise of group g:
  91.     groupStates[g] = f
  92.     
  93.   end repeat
  94.   
  95.   --------------------
  96.   
  97.   -- pass back my address:
  98.   return me
  99.   
  100.   ----------------------------------------------------------------------------------------------------
  101.   
  102. on getConditionStates me
  103.   
  104.   -- establish the status of all specified conditions:
  105.   cL = [:]
  106.   repeat with i = 1 to count(elements)
  107.     
  108.     -- obtain the ith condition name and criteria listing:
  109.     cn = getPropAt(elements,i)
  110.     cd = getAt(elements,i)
  111.     
  112.     -- store the determined state of the condition cn:
  113.     cL[cn] = me.getConditionState(cd)
  114.     
  115.   end repeat  
  116.   
  117.   -- pass compiled listing back to caller:
  118.   return cL
  119.   
  120.   ----------------------------------------------------------------------------------------------------
  121.   
  122. on getConditionState me,cd
  123.   
  124.   -- just one of the criterion listed within cd can be met in order for the condition as a whole
  125.   -- to be fulfilled:
  126.   
  127.   -- examine each criterion in the listing (cd) supplied:
  128.   repeat with i = 1 to count(cd)
  129.     
  130.     -- extract the ith criterion's name and value:
  131.     xn = getPropAt(cd,i)
  132.     xd = getAt(cd,i)
  133.     
  134.     -- process the criterion xn according to its name:
  135.     case xn of
  136.         
  137.       #winRegKey:
  138.         
  139.         -- stop when first successful registry entry is obtained:
  140.         if me.winRegKeyTest(xd) then return 1
  141.         
  142.       #platformTest:
  143.         
  144.         -- what is the current host?     
  145.         um = main.getUtilityMethods()
  146.         p  = um.thePlatform()
  147.         
  148.         -- does the current platform symbol match the one specified by xd?
  149.         if (p = xd) then return 1
  150.         
  151.       #osTest:
  152.         
  153.         -- obtain the operating system name:
  154.         xm    = main.getXtrasManager()
  155.         buddy = xm.getBuddyAPIxtra()
  156.         os    = buddy.getOSName()
  157.         
  158.         -- Windows 2000 returns "Win2000";
  159.         -- Windows NT4 returns "WinNT";
  160.         -- Windows 98 and Windows ME each return "Win98"
  161.         -- Windows 95 returns "Win95"
  162.         
  163.         -- does the current operating system name commence with the string xd?
  164.         if (os starts xd) then return 1
  165.         
  166.     end case
  167.        
  168.   end repeat
  169.   
  170.   -- we reach this point when any none of the above criteria succeed:
  171.   return 0
  172.    
  173.   ----------------------------------------------------------------------------------------------------
  174.   
  175. on winRegKeyTest me,xd
  176.   
  177.   -- we need to check the windows registry for an entry which fulfils the requirements listed in xd:
  178.   
  179.   -- for this we can use the buddyAPIxtra:      
  180.   xm = main.getXtrasManager()
  181.   buddy = xm.getBuddyAPIxtra()
  182.   
  183.   --------------------
  184.   
  185.   -- extract the windows registry criteria listed within xd:
  186.   
  187.   -- which branch of the registry is to be looked in?
  188.   b = xd[#branch]
  189.   
  190.   -- what key location should we examine?
  191.   k = xd[#key] 
  192.   
  193.   -- any particular value name in particular?
  194.   n  = xd[#name]
  195.   
  196.   -- what would constitute a matching valueName?
  197.   nm = xd[#nameMatch]
  198.   
  199.   -- any particular value required for n?
  200.   v  = xd[#value]
  201.   
  202.   -- and how precise do we need to be when matching the value v with what's in the registry?
  203.   vm = xd[#valueMatch]
  204.   
  205.   --------------------
  206.   
  207.   -- first, determine whether the specified registry branch & key exist:
  208.   L = buddy.getRegistryValueNames([#branch:b, #keyName:k]) 
  209.   if L = [] then return 0
  210.   
  211.   --------------------
  212.   
  213.   -- was any value name provided for further investigation?
  214.   -- if not, then we're done ...
  215.   if voidP(n) then return 1
  216.   
  217.   -- ie: confirming the key's existence was all that was needed
  218.   
  219.   --------------------
  220.   
  221.   -- was an exact match located?
  222.   nf = getPos(L,n)
  223.   
  224.   -- and was a valueName match criteria (nm) specified?
  225.   if voidP(nm) then return nf
  226.   
  227.   -- ie: the exact specified value name either was or wasn't found, and that was enough
  228.   
  229.   --------------------
  230.   
  231.   -- nm affects how fussy we should be in trying to 'find' the value name n: 
  232.   case nm of
  233.       
  234.     #exact:
  235.       
  236.       -- we need to find a precise match within L in order to continue:
  237.       if not nf then return 0
  238.       
  239.     #startsWith:
  240.       
  241.       -- recurse over the list L looking for value names beginning with n:
  242.       matchFlag = 0
  243.       repeat with i in L
  244.         
  245.         if i starts n then
  246.           
  247.           -- we found a 'match'!
  248.           matchFlag = 1
  249.           exit repeat
  250.           
  251.         end if
  252.         
  253.       end repeat
  254.       
  255.       -- fail if we didn't get a value name starting with n:
  256.       if not matchFlag then return 0
  257.       
  258.       -- we  found a 'match' with the ith inspected value name -
  259.       -- let's modify our value of n accordingly before continuing:
  260.       n = i
  261.       
  262.   end case
  263.   
  264.   --------------------
  265.   
  266.   -- what value (if any) does the value n need to have?
  267.   
  268.   -- if none is specified, our tests are complete:
  269.   if voidP(v) then return 1
  270.   
  271.   --------------------
  272.   
  273.   -- a value (v) is specified - what one have we got in the registry?
  274.   s = buddy.getRegistryString([#branch:b, #keyName:k, #valueName:n])
  275.   
  276.   -- do we have any information about what constitutes a matching value?
  277.   if voidP(vm) then
  278.     
  279.     -- no value match criteria was provided, so just look for an exact match,
  280.     -- and return the result:  
  281.     return (s = v)
  282.     
  283.   else
  284.     
  285.     -- a match criteria was specified - check it out:
  286.     case vm of
  287.         
  288.       #any:
  289.         
  290.         -- that's it - we're sorted:
  291.         return 1
  292.         
  293.       #startsWith:
  294.         
  295.         -- the value we found in the registry only has to begin with the string that
  296.         -- is specified by v:
  297.         return (s starts v)
  298.         
  299.       otherwise
  300.         
  301.         -- I don't know how to deal with any other match criteria -
  302.         -- assume failure:
  303.         return 0
  304.         
  305.     end case
  306.     
  307.   end if
  308.   
  309.   --------------------
  310.   
  311.   -- we never get here:
  312.   return 1
  313.   
  314.   ----------------------------------------------------------------------------------------------------
  315.   
  316. on testCondition me,c
  317.   
  318.   -- provide caller with the last known status of the condition called c:
  319.   s = conditionStates[c]
  320.   
  321.   -- unknown conditions produce a zero:
  322.   if voidP(s) then s = 0
  323.   
  324.   return s
  325.   
  326.   ----------------------------------------------------------------------------------------------------
  327.   
  328. on evalOutcome me,L
  329.   
  330.   -- (1) extract and check arguments:
  331.   
  332.   -- check for a parameter list:
  333.   if ilk(L) <> #propList then return ┬¼
  334.   [#error:#noParamListSupplied, #msg:"conditionsService:evalOutcome"]
  335.   
  336.   -- an outcome ID is needed:
  337.   id = L[#outcomeID]
  338.   if not symbolP(id) then return ┬¼
  339.   [#error:#noOutcomeIDSupplied, #msg:"conditionsService:evalOutcome"]
  340.   
  341.   -- the id must be known to us:
  342.   gL = outcomes[id]
  343.   
  344.   if ilk(gL) <> #propList then return ┬¼
  345.   [#error:#unknownOutcomeID, #msg:"conditionsService:evalOutcome: ID =" && id]
  346.   
  347.   --------------------
  348.   
  349.   -- test for the status of each condition group belonging to the outcome known as (id):
  350.   repeat with i = 1 to count(gL)
  351.     
  352.     -- pull ith groupName and glueID:
  353.     groupID = getPropAt(gL,i)
  354.     glueID  = getAt(gL,i)
  355.     
  356.     -- is this a valid group?
  357.     s = groupStates[groupID]
  358.     
  359.     -- unrecognised groups are considered invalid:
  360.     if voidP(s) then s = 0
  361.     
  362.     -- skip invalid groups:
  363.     if not s then next repeat
  364.     
  365.     -- if we get here, then we've found a valid condition group -
  366.     -- the outcome is a glue call to application code...   
  367.     return glue(glueID)
  368.     
  369.   end repeat
  370.   
  371.   -- if we got here, there was no valid outcome for the outcomeID supplied to us (oops):
  372.   return ┬¼
  373.   [#error:#unevaluatedOutcome, #msg:"conditionsService:evalOutcome: ID =" && id]
  374.   
  375.   ----------------------------------------------------------------------------------------------------